clear
**SET WORKING DIRECTORY TO SOURCE LOCATION

use "censusdata.dta"


*########## TABLE 5: ETHNIC ENUMERATION AND ETHNIC CIVIL WAR, VARYING LAGS AND PLACEBO TESTS ##########

tsset
eststo clear

foreach lag in 5 10 15 20 30 {


reg newethonset L`lag'.census_total gdpcapl10 lpopl colbrit colfra anocl regchg3 polity2l lrexclpop oilpcl ///
lmtnest npeaceyears ethwarhistb i.region indeplag year nspline1 nspline2 nspline3,robust cluster (ccodecow)

eststo

}


foreach lag in 5 10 15 20  30 {

reg L`lag'.newethonset census_total gdpcapl10 lpopl colbrit colfra anocl regchg3 polity2l lrexclpop oilpcl ///
lmtnest npeaceyears ethwarhistb i.region indeplag year nspline1 nspline2 nspline3,robust cluster (ccodecow)
eststo

}


esttab using placebo.rtf, keep(L5.census_total L10.census_total L15.census_total L20.census_total L30.census_total ) ///
 label title("Ethnic Enumeration and Ethnic Civil War, Varying Lags and Placebo Tests") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05 ** 0.01) nonumbers eqlabels("")

esttab using placebo2.rtf, keep(census_total) ///
 label title("Ethnic Enumeration and Ethnic Civil War, Varying Lags and Placebo Tests") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05 ** 0.01) nonumbers eqlabels("")

*########## TABLE 6: Logit Estimates of Ethnic Enumeration as Predictor of Ethnonationalist Wars (1816�2001) ##########

clear
use "census_merge_wimmer_min.dta", clear

replace gdppcl = gdppcl/1000

tsset
eststo clear
logit bigethonset L.census_any gdppcl lnpopl year, ///
nolog cluster(cowcode)
eststo

logit bigethonset L.census_any gdppcl lnpopl oilpcl ///
lmtnest  anocl asia eeurop lamerica ssafrica nsfyear year, ///
nolog cluster(cowcode)
eststo

logit bigethonset L.census_any ethfrac gdppcl lnpopl oilpcl ///
lmtnest  anocl democl instabl asia eeurop lamerica ssafrica nsfyear year, ///
nolog cluster(cowcode)
eststo

logit bigethonset L.census_total gdppcl lnpopl year, ///
nolog cluster(cowcode)
eststo

logit bigethonset L.census_total gdppcl lnpopl oilpcl ///
lmtnest  anocl asia eeurop lamerica ssafrica nsfyear year, ///
nolog cluster(cowcode)
eststo


logit bigethonset L.census_total ethfrac gdppcl lnpopl oilpcl ///
lmtnest  anocl democl instabl asia eeurop lamerica ssafrica nsfyear year, ///
nolog cluster(cowcode)
eststo


esttab using census_wimmer1.rtf, keep(L.census_any L.census_total gdppcl ethfrac lnpopl oilpcl lmtnest anocl democl instabl) ///
 label title("Logit Estimates of the effect of Ethnic Enumeration on Ethno-Nationalist Wars (Wimmer)") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05) nonumbers eqlabels("")



*########## TABLE 7: Estimates of the effect of Ethno-Nationalist Wars (Wimmer) on likelihood of Ethnic Enumeration ##########
** Placebo test

tsset
eststo clear

logit census_any bigwarspre45 if year>1945, robust cluster(cowcode)
eststo
ologit census_total bigwarspre45 if year>1945, robust cluster(cowcode)
eststo
logit census_any bigwarspre45 ethfrac  gdppcl lnpopl oilpcl ///
lmtnest  anocl year if year>1945, robust cluster(cowcode)
eststo
ologit census_total bigwarspre45 ethfrac  gdppcl lnpopl oilpcl ///
lmtnest  anocl year if year>1945, robust cluster(cowcode)
eststo
esttab using census_wimmer2.rtf, keep(bigwarspre45 ethfrac gdppcl lnpopl) ///
 label title("Estimates of the effect of Ethno-Nationalist Wars (Wimmer) on likelihood of Ethnic Enumeration") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05) nonumbers eqlabels("")

***************************************************************
*** ADDL FOR APPENDIX

clear
use "censusdata.dta"

*########## TABLE A1: SUMMARY STATISTICS ##########


sutex census_any census_total census_race census_tribethoth census_relig census_lang census_caste census_indig gdpcapl lpopl indeplag regchg3 anocl polity2 lrc cens_lr  oilpcl lrexclpop groups newethonset npeaceyears if year>1945 & year<2006 & indeplag~=., labels minmax nobs
sutex marcomb comcon_max_r if year==decade & year>1945 & year<2006 & indeplag~=., labels minmax nobs
sutex vanviolconf vanethb vaninstconf vaninstethb ethfrac relfrac al_ethnic al_language al_religion pregb if year==1995, labels minmax nobs


*########## TABLE A2: Ordered Logits ##########
* make sure to install relogit package from http://gking.harvard.edu/relogit

eststo clear

ologit vanviolconf census_any_lag1 gdpcapl10 lpopl i.region indeplag if year==1995
eststo

ologit comcon_max_r census_any_lag1 gdpcapl10 lpopl i.region indeplag decade if year==decade, robust cluster (ccodecow)
eststo

esttab using census_ologapp.tex, keep(census_any_lag1 gdpcapl10 lpopl indeplag) ///
 label title("Ordered Logit Estimates of the effect of Ethnic Enumeration on Ethnic Violence") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05) nonumbers eqlabels("")



*########## TABLE A10: RARE EVENTS LOGIT ESTIMATES OF ETHNIC ENUMERATION AS PREDICTOR OF ETHNIC ARMED CONFLICT (1946-2005) ##########

xi i.region

eststo clear

logit newethonset census_any_lag1 gdpcapl10 lpopl year _Iregion* indeplag nspline* , ///
cluster(ccodecow)

eststo


relogit newethonset census_any_lag1 gdpcapl10 lpopl year _Iregion* indeplag nspline* , ///
cluster(ccodecow)

eststo
esttab using relogests.tex, keep(census_any_lag1 gdpcapl10 lpopl year _Iregion* indeplag) ///
 label title("Rare Events Logit Estimates of the effect of Ethnic Enumeration") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05) nonumbers eqlabels("")




*########## TABLE A11: LOGIT ESTIMATES OF THE INTERACTION OF ETHNIC ENUMERATION AND CROSS CUTTING ETHNIC CLEAVAGES ON OUTBREAK OF ETHNIC CIVIL WAR (1946-2005) ##########

*########## FIGURE A4: ENUMERATION OF RELIGION AND LANGUAGE CATEGORIES AS PREDICTORS OF LIKELIHOOD OF NEW ETHNIC ARMED CONFLICT ONSET, CONDITIONAL ON DEGREE OF CROSS-CUTTINGNESS ##########


**Selway cross-cutting (Thanks to Joel Selway for sharing code *****
 
**
tsset ccodecow year
eststo clear
logit newethonset L.cens_lr lrc census_cc gdpcapl lpopl ///
lmtnest  regchg3 anocl oilpcl ongoingwarl i.decade npeaceyears nspline* , ///
nolog cluster(ccodecow)
eststo
esttab using census_relevance_reg.tex, keep(L.cens_lr lrc census_cc gdpcapl lpopl ///
lmtnest  regchg3 anocl oilpcl) ///
 label title("Logit Estimates of the Interaction of Ethnic Enumeration and Cross Cutting Ethnic Cleavages on Outbreak of Ethnic Civil War") addnote( "L. indicates lagged one year ") se  replace star(+ 0.10 * 0.05) nonumbers eqlabels("")



#delimit ;

egen zmin = min (lrc);
egen zmax = max(lrc);
gen MV = (((_n-1)/(20-1))*(zmax-zmin))+zmin in 1/20;

*     ****************************************************************  *;
*       Grab elements of the coefficient and variance-covariance matrix *;
*       that are required to calculate the marginal effect and standard *;
*       errors.                                                         *;
*     ****************************************************************  *;

matrix b=e(b); 
matrix V=e(V);
 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];


scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];

scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3;

*     ****************************************************************  *;
*       Calculate the marginal effect of X on Y for all MV values of    *;
*       the modifying variable Z.                                       *;
*     ****************************************************************  *;

gen conb=b1+b3*MV;


*     ****************************************************************  *;
*       Calculate the standard errors for the marginal effect of X on Y *;
*       for all MV values of the modifying variable Z.                  *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV); 


*     ****************************************************************  *;
*       Generate upper and lower bounds of the confidence interval.     *;
*       Specify the significance of the confidence interval.            *;
*     ****************************************************************  *;

gen a=1.96*conse;
 
gen upper=conb+a;
 
gen lower=conb-a;

*     ****************************************************************  *;
*       Graph the marginal effect of X on Y across the desired range of *;
*       the modifying variable Z.  Show the confidence interval.        *;
*     ****************************************************************  *;

graph twoway line conb   MV, clwidth(medium) clcolor(blue) clcolor(black)
        ||   line upper  MV, clpattern(dash) clwidth(vthin) clcolor(black)
        ||   line lower  MV, clpattern(dash) clwidth(vthin) clcolor(black)
        ||   ,   
        	 legend(off)
	         yline(0, lcolor(black))   
             xtitle(Ethno-Religious Crosscuttingness, size(3)  )
             ytitle("Marginal Effect of Ethnic Institutionalization on Violence", size(3))
             scheme(s2mono) graphregion(fcolor(white));
             
drop zmin zmax MV conb conse a upper lower;


